<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>业务统计</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
        .fieldBox{width: 100%;}
        .timeCss{display: inline-block;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">项目类型</div>
                    <div class="field">
		    			<div id="prjTypRadioList"></div>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">查询时间</div>
                    <div class="field">
                        <div id="tmTypRadioList"></div>
                        <input ligerui="width: 120" name="startTm"
						id="startTm" type="text" class="ui-datepicker" value=""
						validate="{required:true}"> - <input
						ligerui="width: 120" name="endTm" id="endTm"
						type="text" class="ui-datepicker" value=""
						validate="{required:true}">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,form=null;
    var groupId = ${groupId};
	var splTypCd = ${splTypCd};

	//总计
    var totalPayNumSum = null;//累计合作支付表
    var totalDevAmtSum = null;//累计投放
    var hisBkPayNumSum = null;//累计30+和拖回 支付表数
    var hisBkDevAmtSum = null;//累计30+和拖回 投放额
    var repayPayNumSum = null;//在还支付表数
    var repayExpoAmtSum = null;//在还敞口
    var repayBkPayNumSum = null;//在还30+和拖回 支付表数
    var repayBkExpoAmtSum = null;//在还30+和拖回 敞口

    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/grpcfg/splgrpprjbizview/initList.do?groupId='+groupId,
            method: 'get',
            parms:{
                groupId:groupId,
                splTypCd:splTypCd
            },
            columns: [
                {display: '所在集团', name: 'splNm', width: 200, align: 'center', enabledSort: false,
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                			return '总计';
                		}
                	}
                },
                {display: '成员名称', name: 'compNm', width: 200, align: 'center', enabledSort: false,},
                {display: '累计合作支付表', name: 'totalPayNum', width: 120, align: 'center',enabledSort: false,
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                            totalPayNumSum = suminf.sum;
                			return totalPayNumSum;
                		}
                	}
                },
                {display: '累计投放(元)', name: 'totalDevAmt', width: 120, align: 'center',
                    render: function (rowdata, index, value) {
                        return '¥'+FormatMoney(rowdata.totalDevAmt / 100);
                    },
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                		    totalDevAmtSum = suminf.sum;
                            return '¥'+FormatMoney(totalDevAmtSum / 100);
                		}
                	}
                },
                {display: '累计30+和拖回', columns:
                    [
                        {display: '支付表数', name: 'hisBkPayNum', width: 80, align: 'center',
                        	totalSummary: {
                        		type: 'sum',
                        		render : function(suminf, column, cell){
                        		    hisBkPayNumSum = suminf.sum;
                        			return suminf.sum;
                        		}
                        	}
                        },
                        {display: '比率', name: '', width: 80, align: 'center',
                            render:function(rowdata,index,value){
                            	if (!rowdata.totalPayNum){
                            		return ;
                            	}
                                return percentNum(rowdata.hisBkPayNum,rowdata.totalPayNum);
                            },
                            totalSummary: {
                                type: 'sum',
                                render:function(rowdata,index,value){
                                    if (!totalPayNumSum){
                                        return ;
                                    }
                                    return percentNum(hisBkPayNumSum,totalPayNumSum);
                                }
                            }

                        },
                        {display: '投放额', name: 'hisBkDevAmt', width: 120, align: 'center',
                            render: function (rowdata, index, value) {
                                return '¥'+FormatMoney(rowdata.hisBkDevAmt / 100);
                            },
                        	totalSummary: {
                        		type: 'sum',
                        		render : function(suminf, column, cell){
                        		    hisBkDevAmtSum = suminf.sum;
                                    return '¥'+FormatMoney(hisBkDevAmtSum / 100);
                        		}
                        	}
                        },
                        {display: '比率', name: '', width: 80, align: 'center',
                        	render:function(rowdata,index,value){
                        		if (!rowdata.totalDevAmt){
                        			return;
                        		}
                                return percentNum(rowdata.hisBkDevAmt,rowdata.totalDevAmt);
                            },
                            totalSummary: {
                                type: 'sum',
                                render:function(rowdata,index,value){
                                    if (!totalDevAmtSum){
                                        return;
                                    }
                                    return percentNum(hisBkDevAmtSum,totalDevAmtSum);
                                }
                            }
                        }
                    ]
                },
                {display: '在还支付表数', name: 'repayPayNum', width: 120, align: 'center',
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                		    repayPayNumSum = suminf.sum;
                			return suminf.sum;
                		}
                	}
                },
                {display: '在还敞口', name: 'repayExpoAmt', width: 120, align: 'center',
                    render: function (rowdata, index, value) {
                        return '¥'+FormatMoney(rowdata.repayExpoAmt / 100);
                    },
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                		    repayExpoAmtSum = suminf.sum;
                            return '¥'+FormatMoney(repayExpoAmtSum / 100);
                		}
                	}
                },
                { display: '在还30+和拖回', columns:
                    [
                        {display: '支付表数', name: 'repayBkPayNum', width: 80, align: 'center',
                        	totalSummary: {
                        		type: 'sum',
                        		render : function(suminf, column, cell){
                        		    repayBkPayNumSum = suminf.sum;
                        			return suminf.sum;
                        		}
                        	}
                        },
                        {display: '比率', name: '', width: 80, align: 'center', 
                        	render:function(rowdata,index,value){
                        		if (!rowdata.repayPayNum){
                        			return;
                        		}
                                return percentNum(rowdata.repayBkPayNum,rowdata.repayPayNum);
                            },
                            totalSummary: {
                                type: 'sum',
                                render:function(rowdata,index,value){
                                    if (!repayPayNumSum){
                                        return;
                                    }
                                    return percentNum(repayBkPayNumSum,repayPayNumSum);
                                }
                            }
                        },
                        {display: '敞口', name: 'repayBkExpoAmt', width: 120, align: 'center',
                            render: function (rowdata, index, value) {
                                return '¥'+FormatMoney(rowdata.repayBkExpoAmt / 100);
                            },
                        	totalSummary: {
                        		type: 'sum',
                        		render : function(suminf, column, cell){
                        		    repayBkExpoAmtSum = suminf.sum;
                                    return '¥'+FormatMoney(repayBkExpoAmtSum / 100);
                        		}
                        	}
                        },
                        {display: '比率', name: '', width: 80, align: 'center',
                            render:function(rowdata,index,value){
                            	if (!rowdata.repayExpoAmt){
                            		return ;
                            	}
                                return percentNum(rowdata.repayBkExpoAmt,rowdata.repayExpoAmt);
                            },
                            totalSummary: {
                                type: 'sum',
                                render:function(rowdata,index,value){
                                    if (!repayExpoAmtSum){
                                        return ;
                                    }
                                    return percentNum(repayBkExpoAmtSum,repayExpoAmtSum);
                                }
                            }
                        }
                    ]
                },
                {display: '账务结余', name: 'arAmt', width: 120, align: 'center',
                    render: function (rowdata, index, value) {
                        if (!value){
                            return '¥0.00';
                        }
                        return '¥'+FormatMoney(rowdata.arAmt / 100);
                    },
                	totalSummary: {
                		type: 'sum',
                		render : function(suminf, column, cell){
                            return '¥'+FormatMoney(suminf.sum / 100);
                		}
                	}
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            //usePager: false,
            headerRowHeight: 35,
            /*delayLoad: true*/
        });
        grid.setHeight(100);

        form=$("#searchBar").ligerForm();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            //console.log($('#startTm').val());
            var prjTypCd = liger.get("prjTypRadioList").getValue();
            var tmTypCd = liger.get("tmTypRadioList").getValue();
            var startTm = $('#startTm').val();
            var endTm = $('#endTm').val();
            grid.setParm('prjTypCd', prjTypCd);
            grid.setParm('tmTypCd', tmTypCd);
            grid.setParm('startTm', startTm);
            grid.setParm('endTm', endTm);
            grid.reload();
            //getValue();
        });

        /* 清空 */
        $("#clearBtn").click(function(event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "prjTypCd":"",
                "tmTypCd":"",
                "startTm":"",
                "endTm":""
            });
        });
        
        function getValue(){
			var value = liger.get("prjTypRadioList").getValue();
			console.log(value);
			return value;
		}
        
        var dataGrid = [
			{ id: 'CTYW', name: '传统业务'},
			{ id: 'CPYW', name: '城配业务'},
			{ id: 'CDDYW', name: '车抵贷'},
			{ id: 'ALL', name: '以上全部'},
		]; 
        
		$("#prjTypRadioList").ligerRadioList({
			data: dataGrid,
			textField: 'name',
			valueField: 'id',
			rowSize: 10,
		});
		
		var dataGrid2 = [
			{ id: 1, name: '近一个月'},
			{ id: 3, name: '近三个月'},
			{ id: 6, name: '近六个月'},
			{ id: 12, name: '近一年'},
			{ id: 0, name: '自定义时间' },
		]; 
        
		$("#tmTypRadioList").ligerRadioList({
			data: dataGrid2,
			textField: 'name',
			valueField: 'id',
			rowSize: 10,
			css: 'timeCss',
		});

    });


    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    function percentNum(num,num2) {
        return (Math.round(num / num2 * 10000) / 100.00 + "%"); //小数点后两位百分比
    }

</script>

</body>
</html>
